/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.change.study.data.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Simple class that represents any User domain entity in any application.
 *
 * <p>
 * Because this class performs its own Realm and Permission checks, and these
 * can happen frequently enough in a production application, it is highly
 * recommended that the internal User {@link #getRoles} collection be cached in
 * a 2nd-level cache when using JPA and/or Hibernate. The hibernate xml
 * configuration for this sample application does in fact do this for your
 * reference (see User.hbm.xml - the 'roles' declaration).
 * </p>
 */
@Entity
@Table(name = "user")
public class User implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue
	private Long id;

	@Basic(optional = false)
	@Column(length = 100)
	private String username;
	
	private String name;

	private String phonenum;

	private String headimg;
	
	
	@Column(length=100)
	private String bgimg;

	private String qq;

	private String city;

	private String introduction;

	@Basic(optional = false)
	@Column(nullable=true)
	private String email;

	@Basic(optional = false)
	@Column(length = 255)
	@JsonIgnore
	private String password;

	private String macaddress;

	private Date addDate;
	
	private Date lastDate;

	
	private Integer logintimes;
	
	private String avatar = "";
	private String slogan = "";
	private String tags = "";
	private String tags_str = "";
	private String company = "";
	private String global_key = "";
	private String job_str = "";
	private String lavatar = "";
	private String location = "";
	private String phone = "";
	private String birthday = "";
    
	
	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public String getSlogan() {
		return slogan;
	}

	public void setSlogan(String slogan) {
		this.slogan = slogan;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public String getTags_str() {
		return tags_str;
	}

	public void setTags_str(String tags_str) {
		this.tags_str = tags_str;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getGlobal_key() {
		return global_key;
	}

	public void setGlobal_key(String global_key) {
		this.global_key = global_key;
	}

	public String getJob_str() {
		return job_str;
	}

	public void setJob_str(String job_str) {
		this.job_str = job_str;
	}

	public String getLavatar() {
		return lavatar;
	}

	public void setLavatar(String lavatar) {
		this.lavatar = lavatar;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "users_role_links")
	private Set<UserRole> roles = new HashSet<UserRole>();

	@JsonIgnore
	private String salt; // 加密密码的盐

	private String plainPassword;

	public Date getAddDate() {
		return addDate;
	}

	public String getBgimg() {
		return bgimg;
	}
	public String getCity() {
		return city;
	}

	@JsonIgnore
	@Transient
	public String getCredentialsSalt() {
		return username + salt;
	}


	public String getEmail() {
		return email;
	}

	
	public String getHeadimg() {
		return headimg;
	}


	public Long getId() {
		return id;
	}

	
	public String getIntroduction() {
		return introduction;
	}
	public Date getLastDate() {
		return lastDate;
	}
	
	public Integer getLogintimes() {
		return logintimes;
	}
	public String getMacaddress() {
		return macaddress;
	}
	public String getName() {
		return name;
	}

	/**
	 * Returns the password for this user.
	 *
	 * @return this user's password
	 */

	public String getPassword() {
		return password;
	}

	public String getPhonenum() {
		return phonenum;
	}

	// 不持久化到数据库，也不显示在Restful接口的属性.
	@Transient
	@JsonIgnore
	public String getPlainPassword() {
		return plainPassword;
	}



	public String getQq() {
		return qq;
	}

	public Set<UserRole> getRoles() {
		return roles;
	}

	public String getSalt() {
		return salt;
	}

	/**
	 * Returns the username associated with this user account;
	 *
	 * @return the username associated with this user account;
	 */

	public String getUsername() {
		return username;
	}

	public void setAddDate(Date addDate) {
		this.addDate = addDate;
	}


	public void setBgimg(String bgimg) {
		this.bgimg = bgimg;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setHeadimg(String headimg) {
		this.headimg = headimg;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}

	public void setLogintimes(Integer logintimes) {
		this.logintimes = logintimes;
	}

	public void setMacaddress(String macaddress) {
		this.macaddress = macaddress;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setPhonenum(String phonenum) {
		this.phonenum = phonenum;
	}

	public void setPlainPassword(String plainPassword) {
		this.plainPassword = plainPassword;
	}


	public void setQq(String qq) {
		this.qq = qq;
	}

	public void setRoles(Set<UserRole> roles) {
		this.roles = roles;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	public void setUsername(String username) {
		this.username = username;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", profile=" + ", username="
				+ username + ", name=" + name + ", phonenum=" + phonenum
				+ ", email=" + email + ", password=" + password
				+ ", macaddress=" + macaddress + ", addDate=" + addDate
				+ ", lastDate=" + lastDate + ", logintimes=" + logintimes
				+ ", roles=" + roles + ", salt=" + salt + ", plainPassword="
				+ plainPassword + "]";
	}

}
